package com.datastructure.test.continueofplayingcard;

import java.util.Arrays;

public class ContinueOfPlayingCard {

    public static void main(String[] args) {
        ContinueOfPlayingCard continueOfPlayingCard = new ContinueOfPlayingCard();
        int[] data = {11,10,0,0,12};
        boolean isContinuous = continueOfPlayingCard.IsContinuous(data);
        System.out.println(isContinuous);
    }

    public boolean IsContinuous(int [] numbers) {
        Arrays.sort(numbers);
        int numberOfZero = 6;
        int sum = 0;
        for (int i = 0; i < numbers.length; i++) {
            if(numbers[i]!=0){
                numberOfZero=i;
                break;
            }
        }
        if(numberOfZero==6){
            return false;
        }
        int[] newArray = new int[numbers.length-numberOfZero];
        if(newArray.length==1){
            return true;
        }
        System.arraycopy(numbers,numberOfZero,newArray,0,newArray.length);
        for (int i = 0; i < newArray.length; i++) {
            if(i>0){
                sum+=(newArray[i]-newArray[i-1]-1);
            }
            if(i>0&&newArray[i]==newArray[i-1]){
                return false;
            }
        }
        if(sum==0){
            return true;
        }
        if(sum!=numberOfZero){
            return false;
        }
        return true;
    }
}
